package cn.itcast.order.service;

import cn.itcast.order.mapper.OrderMapper;

import com.cwj.openfign.config.UserFeignClient;
import com.cwj.openfign.pojo.Order;
import com.cwj.openfign.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    UserFeignClient userFeignClient;

//    @Autowired
//    RestTemplate restTemplate;

    public Order queryOrderById(Long orderId) {
        // 1.查询订单
        Order order = orderMapper.findById(orderId);

        User user = userFeignClient.queryOrderByUserId(order.getUserId());
        System.out.println(user);

        // 4.返回
////        2、获取用户id
//        Long userId = order.getUserId();
////        3、根据用户id结合注册中心的name进行服务发现，填写提供者的service就行
//        String url="http://user-service/user/"+userId;
//        User user = restTemplate.getForObject(url, User.class);
//        4、封装数据
        order.setUser(user);
        return order;
    }
}
